<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-10 offset-lg-1">
	
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active(array(
					'set'=>array('url'=>url('plugin-setting-xn_search-set'), 'text'=>lang('admin_setting_search_set')),
					'cutword'=>array('url'=>url('plugin-setting-xn_search-cutword'), 'text'=>lang('admin_setting_search_cutword'))
				), $action);?>
		</div>
		
		<div class="card">
			<div class="card-block">
				<form action="<?php echo url("plugin-setting-xn_search");?>" method="post" id="form">
					<div class="form-group row">
						<label class="col-sm-2 form-control-label">搜索类型：</label>
						<div class="col-sm-10">
							<?php echo $input['type']; ?>
						</div>
					</div>
					<div class="form-group row" id="fulltext">
						<label class="col-sm-2 form-control-label">中文切词 API：</label>
						<div class="col-sm-10">
							<?php echo $input['cutword_url']; ?>
							<p class="text-grey text-small">默认为官方的切词服务 API，可以自行搭建、或者指定第三方切词服务 API</p>
							<p class="small text-danger">注：为了支持中文两个字搜索，请设置 my.ini 中的 <b>ft_min_word_len</b> = 2，并重启 mysql 服务</p>
						</div>
					</div>
					<div id="sphinx">
						<div class="form-group row">
							<label class="col-sm-2 form-control-label">Sphinx IP：</label>
							<div class="col-sm-10">
								<?php echo $input['sphinx_host']; ?>
								<p class="text-grey text-small">需要自行配置 Sphinx，参考文档：<a href="http://bbs.xiuno.com/thread-18.htm" target="_blank">http://bbs.xiuno.com/thread-18.htm</a></p>
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-2 form-control-label">Sphinx 端口：</label>
							<div class="col-sm-10">
								<?php echo $input['sphinx_port']; ?>
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-2 form-control-label">Sphinx 索引：</label>
							<div class="col-sm-10">
								<?php echo $input['sphinx_index']; ?>
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-2 form-control-label">Sphinx 增量索引：</label>
							<div class="col-sm-10">
								<?php echo $input['sphinx_delta_index']; ?>
							</div>
						</div>
					</div>
					<div class="form-group row" id="site_url">
						<label class="col-sm-2 form-control-label">第三方搜索 URL：</label>
						<div class="col-sm-10">
							<?php echo $input['site_url']; ?>
							<p class="text-grey text-small">URL 中的 {keyword} 为关键字</p>
						</div>
					</div>
					
					<div class="form-group row" id="range">
						<div class="form-group row">
							<label class="col-sm-2 form-control-label">开启搜索范围：</label>
							<div class="col-sm-10">
								<?php echo $input['range']; ?>
							</div>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 form-control-label"></label>
						<div class="col-sm-10">
							<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('confirm');?></button>
							<a role="button" class="btn btn-secondary btn-block m-t-1" href="javascript:history.back();"><?php echo lang('back');?></a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>

var jform = $("#form");
var jsubmit = $("#submit");
var referer = '<?php echo http_referer();?>';
jform.on('submit', function(){
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.text(message).delay(2000).button('reset').location(referer);
			return;
		} else {
			$.alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});

function search_type_radio_check(v) {
	var jfulltext = $('#fulltext');
	var jsphinx = $('#sphinx');
	var jsite_url = $('#site_url');
	var jrange = $('#range');
	if(v == 'fulltext') {
		jfulltext.show();
		jsphinx.hide();
		jsite_url.hide();
		jrange.show();
	} else if(v == 'like') {
		jfulltext.hide();
		jsphinx.hide();
		jsite_url.hide();
		jrange.show();
	} else if(v == 'sphinx') {
		jfulltext.hide();
		jsphinx.show();
		jsite_url.hide();
		jrange.hide();
	} else if(v == 'site_url') {
		jfulltext.hide();
		jsphinx.hide();
		jsite_url.show();
		jrange.hide();
	}
}
jform.find('input[name="type"]').on('click', function() {
	var v = $(this).val();
	search_type_radio_check(v);
});
search_type_radio_check(jform.find('input[name="type"]').checked());
</script>